import 'package:ducafe_ui_core/ducafe_ui_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:get/get.dart';
import 'dart:math' as math;

import '../../common/index.dart';
import 'index.dart';

class AiPage extends StatefulWidget {
  const AiPage({super.key});

  @override
  State<AiPage> createState() => _AiPageState();
}

class _AiPageState extends State<AiPage> with TickerProviderStateMixin {
  late final AnimationController _outerRotationController;
  late final AnimationController _pulseController;
  late final AnimationController _innerRotationController;
  late final AnimationController _scaleController;
  late final AnimationController _shimmerController;

  late final Animation<double> _outerRotationAnimation;
  late final Animation<double> _pulseAnimation;
  late final Animation<double> _innerRotationAnimation;
  late final Animation<double> _scaleAnimation;
  late final Animation<double> _shimmerAnimation;

  AiController get controller => Get.find<AiController>();

  @override
  void initState() {
    super.initState();

    // 外圈旋转动画控制器
    _outerRotationController = AnimationController(
      duration: const Duration(milliseconds: 3000),
      vsync: this,
    )..repeat();
    _outerRotationAnimation = Tween<double>(
      begin: 0,
      end: 2 * math.pi,
    ).animate(_outerRotationController);

    // 脉冲效果控制器
    _pulseController = AnimationController(
      duration: const Duration(milliseconds: 1500),
      vsync: this,
    )..repeat(reverse: true);
    _pulseAnimation = Tween<double>(begin: 1.0, end: 1.2).animate(
      CurvedAnimation(parent: _pulseController, curve: Curves.easeInOut),
    );

    // 内部旋转点控制器
    _innerRotationController = AnimationController(
      duration: const Duration(milliseconds: 5000),
      vsync: this,
    )..repeat();
    _innerRotationAnimation = Tween<double>(
      begin: 0,
      end: 2 * math.pi,
    ).animate(_innerRotationController);

    // 中心点缩放控制器
    _scaleController = AnimationController(
      duration: const Duration(milliseconds: 1200),
      vsync: this,
    )..repeat(reverse: true);
    _scaleAnimation = Tween<double>(begin: 0.8, end: 1.0).animate(
      CurvedAnimation(parent: _scaleController, curve: Curves.easeInOut),
    );

    // 进度条光效控制器
    _shimmerController = AnimationController(
      duration: const Duration(milliseconds: 1500),
      vsync: this,
    )..repeat();
    _shimmerAnimation = Tween<double>(begin: -50, end: 250).animate(
      CurvedAnimation(parent: _shimmerController, curve: Curves.linear),
    );
  }

  @override
  void dispose() {
    _outerRotationController.dispose();
    _pulseController.dispose();
    _innerRotationController.dispose();
    _scaleController.dispose();
    _shimmerController.dispose();
    super.dispose();
  }

  // Main view builder
  Widget _buildView() {
    return Obx(() {
      final hasResult =
          controller.plant_name.value.isNotEmpty ||
          controller.result_text.value.isNotEmpty;
      final isLoading = controller.is_loading.value;
      final plantName = controller.plant_name.value;
      final confidence = controller.confidence_score.value;
      final careInfo = controller.care_information.value;
      final floweringTime = controller.flowering_time.value;
      final commonProblems = controller.common_problems.value;
      final resultText = controller.result_text.value;

      if (!hasResult && !isLoading) {
        // 保持原有上传界面和说明内容
        return Column(
          children: [
            SizedBox(height: 145.h),
            Center(
              child: Text(
                "Get Plant Information",
                style: TextStyle(
                  fontSize: 15.sp,
                  fontWeight: FontWeight.w900,
                  color: const Color(0xFFCDFF5F),
                ),
              ),
            ),
            SizedBox(height: 30.h),
            Container(
              width: 265.w,
              height: 40.h,
              decoration: BoxDecoration(
                color: const Color(0xFFF2FBEE),
                borderRadius: BorderRadius.circular(10.r),
                boxShadow: [
                  BoxShadow(
                    color: Colors.black.withOpacity(0.05),
                    blurRadius: 4,
                    offset: const Offset(0, 2),
                  ),
                ],
              ),
              child: Row(
                children: [
                  SizedBox(width: 22.w),
                  Container(
                    width: 32.w,
                    height: 32.h,
                    decoration: const BoxDecoration(
                      color: Color(0xFFCDFF5F),
                      shape: BoxShape.circle,
                    ),
                    child: const Icon(
                      Icons.check,
                      color: Colors.white,
                      size: 18,
                    ),
                  ),
                  SizedBox(width: 8.w),
                  Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Container(
                        width: 100.w,
                        height: 6.h,
                        decoration: BoxDecoration(
                          color: const Color(0xFFCDFF5F),
                          borderRadius: BorderRadius.circular(3.r),
                        ),
                      ),
                      SizedBox(height: 5.h),
                      Container(
                        width: 65.w,
                        height: 6.h,
                        decoration: BoxDecoration(
                          color: const Color(0xFFCDFF5F).withOpacity(0.7),
                          borderRadius: BorderRadius.circular(3.r),
                        ),
                      ),
                      SizedBox(height: 5.h),
                      Container(
                        width: 85.w,
                        height: 6.h,
                        decoration: BoxDecoration(
                          color: const Color(0xFFCDFF5F).withOpacity(0.8),
                          borderRadius: BorderRadius.circular(3.r),
                        ),
                      ),
                    ],
                  ),
                  const Spacer(),
                  SizedBox(width: 10.w),
                ],
              ),
            ),
            SizedBox(height: 55.h),
            Container(
              width: 210.w,
              height: 210.h,
              decoration: BoxDecoration(
                image: const DecorationImage(
                  image: AssetImage(AssetsImages.aiBg),
                  fit: BoxFit.contain,
                ),
                borderRadius: BorderRadius.circular(10.r),
              ),
              child: SvgPicture.asset(AssetsImages.scan),
            ),
            SizedBox(height: 35.h),
            SizedBox(
              width: double.infinity,
              height: 100.h,
              child: Column(
                children: [
                  Text(
                    "Upload plant photos to receive",
                    textAlign: TextAlign.center,
                    style: TextStyle(
                      fontSize: 12.sp,
                      fontWeight: FontWeight.w400,
                      color: const Color(0xFFCDFF5F),
                    ),
                    maxLines: 3,
                  ),
                  Text(
                    "care instructions and problem-solving tips",
                    textAlign: TextAlign.center,
                    style: TextStyle(
                      fontSize: 12.sp,
                      fontWeight: FontWeight.w400,
                      color: const Color(0xFFCDFF5F),
                    ),
                  ),
                  SizedBox(height: 30.h),
                ],
              ),
            ),
            const Spacer(),
            SizedBox(height: 125.h),
          ],
        );
      }

      // 结果展示：只保留顶部标题和结果内容
      final List<Map<String, String>> resultSections = [
        if (plantName.isNotEmpty) {"title": "Name", "content": plantName},
        if (confidence > 0)
          {
            "title": "Confidence",
            "content": "${(confidence * 100).toStringAsFixed(2)}%",
          },
        if (careInfo.isNotEmpty && careInfo.trim() != '' && careInfo != 'null')
          {"title": "Care Info", "content": careInfo},
        if (floweringTime.isNotEmpty &&
            floweringTime.trim() != '' &&
            floweringTime != 'null')
          {"title": "Flowering Time", "content": floweringTime},
        if (commonProblems.isNotEmpty &&
            commonProblems.trim() != '' &&
            commonProblems != 'null')
          {"title": "Common Problems", "content": commonProblems},
        if (resultText.isNotEmpty &&
            !resultText.contains('successfully') &&
            resultText != 'null')
          {"title": "Status", "content": resultText},
      ];

      // Filter out sections with empty or meaningless content
      final filteredSections = resultSections.where((section) {
        final content = section["content"] ?? "";
        return content.isNotEmpty &&
            content.trim() != '' &&
            content != 'null' &&
            content != 'undefined';
      }).toList();

      return SingleChildScrollView(
        physics: const BouncingScrollPhysics(),
        child: Padding(
          padding: EdgeInsets.only(
            bottom: 150.h,
          ), // Bottom padding for upload button
          child: Column(
            children: [
              SizedBox(height: 95.h),
              Center(
                child: Text(
                  "Get Plant Information",
                  style: TextStyle(
                    fontSize: 15.sp,
                    fontWeight: FontWeight.w900,
                    color: const Color(0xFFCDFF5F),
                  ),
                ),
              ),
              SizedBox(height: 20.h),

              // 显示上传的图片
              if (controller.selected_image.value != null)
                Container(
                  width: 120.w,
                  height: 120.h,
                  margin: EdgeInsets.only(bottom: 16.h),
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(15.r),
                    boxShadow: [
                      BoxShadow(
                        color: Colors.black.withOpacity(0.25),
                        blurRadius: 10,
                        offset: const Offset(0, 4),
                      ),
                    ],
                    image: DecorationImage(
                      image: FileImage(controller.selected_image.value!),
                      fit: BoxFit.cover,
                    ),
                  ),
                ),

              SizedBox(height: 10.h),

              // 结果展示区域
              if (isLoading)
                SizedBox(
                  height: 400.h,
                  child: Center(
                    child: TweenAnimationBuilder<double>(
                      duration: const Duration(milliseconds: 800),
                      tween: Tween<double>(begin: 0.9, end: 1.0),
                      curve: Curves.easeInOut,
                      builder: (context, value, child) {
                        return Transform.scale(
                          scale: value,
                          child: Container(
                            padding: EdgeInsets.all(20.r),
                            decoration: BoxDecoration(
                              color: Colors.black.withOpacity(0.7),
                              borderRadius: BorderRadius.circular(20.r),
                              boxShadow: [
                                BoxShadow(
                                  color: const Color(
                                    0xFFCDFF5F,
                                  ).withOpacity(0.3),
                                  spreadRadius: 2,
                                  blurRadius: 10,
                                ),
                              ],
                            ),
                            child: Obx(
                              () => Column(
                                mainAxisSize: MainAxisSize.min,
                                children: [
                                  // Loading indicator content (unchanged)
                                  SizedBox(
                                    width: 70.w,
                                    height: 70.h,
                                    child: Stack(
                                      alignment: Alignment.center,
                                      children: [
                                        // 外圈旋转动画 - 不依赖进度值
                                        AnimatedBuilder(
                                          animation: _outerRotationAnimation,
                                          builder: (context, child) {
                                            return Transform.rotate(
                                              angle:
                                                  _outerRotationAnimation.value,
                                              child: Container(
                                                width: 70.w,
                                                height: 70.h,
                                                decoration: BoxDecoration(
                                                  shape: BoxShape.circle,
                                                  border: Border.all(
                                                    color: const Color(
                                                      0xFFCDFF5F,
                                                    ).withOpacity(0.2),
                                                    width: 2,
                                                  ),
                                                  boxShadow: [
                                                    BoxShadow(
                                                      color: const Color(
                                                        0xFFCDFF5F,
                                                      ).withOpacity(0.1),
                                                      blurRadius: 15,
                                                      spreadRadius: 2,
                                                    ),
                                                  ],
                                                ),
                                                child: Center(
                                                  child: Container(
                                                    width: 8.w,
                                                    height: 8.h,
                                                    decoration:
                                                        const BoxDecoration(
                                                          color: Color(
                                                            0xFFCDFF5F,
                                                          ),
                                                          shape:
                                                              BoxShape.circle,
                                                        ),
                                                  ),
                                                ),
                                              ),
                                            );
                                          },
                                        ),

                                        // 主进度指示器
                                        TweenAnimationBuilder<double>(
                                          duration: const Duration(seconds: 2),
                                          tween: Tween<double>(
                                            begin: 0,
                                            end: 1,
                                          ),
                                          builder: (context, value, child) {
                                            return Stack(
                                              alignment: Alignment.center,
                                              children: [
                                                // 脉冲效果
                                                AnimatedBuilder(
                                                  animation: _pulseAnimation,
                                                  builder: (context, child) {
                                                    return Transform.scale(
                                                      scale:
                                                          _pulseAnimation.value,
                                                      child: Container(
                                                        width: 55.w,
                                                        height: 55.h,
                                                        decoration:
                                                            BoxDecoration(
                                                              shape: BoxShape
                                                                  .circle,
                                                              color:
                                                                  const Color(
                                                                    0xFFCDFF5F,
                                                                  ).withOpacity(
                                                                    0.05,
                                                                  ),
                                                            ),
                                                      ),
                                                    );
                                                  },
                                                ),

                                                // 实际进度圆环
                                                CircularProgressIndicator(
                                                  valueColor:
                                                      const AlwaysStoppedAnimation<
                                                        Color
                                                      >(Color(0xFFCDFF5F)),
                                                  strokeWidth: 5,
                                                  value:
                                                      controller
                                                              .recognition_progress
                                                              .value >
                                                          0
                                                      ? controller
                                                            .recognition_progress
                                                            .value
                                                      : null,
                                                ),

                                                // 内部旋转点
                                                AnimatedBuilder(
                                                  animation:
                                                      _innerRotationAnimation,
                                                  builder: (context, child) {
                                                    return Transform.rotate(
                                                      angle:
                                                          -_innerRotationAnimation
                                                              .value, // 反方向旋转
                                                      child: Transform.translate(
                                                        offset: Offset(15.w, 0),
                                                        child: Container(
                                                          width: 6.w,
                                                          height: 6.h,
                                                          decoration:
                                                              const BoxDecoration(
                                                                color: Color(
                                                                  0xFFFFEE00,
                                                                ),
                                                                shape: BoxShape
                                                                    .circle,
                                                              ),
                                                        ),
                                                      ),
                                                    );
                                                  },
                                                ),
                                              ],
                                            );
                                          },
                                        ),

                                        // 中心百分比文字
                                        if (controller
                                                .recognition_progress
                                                .value >
                                            0)
                                          Text(
                                            "${(controller.recognition_progress.value * 100).toInt()}%",
                                            style: TextStyle(
                                              color: const Color(0xFFCDFF5F),
                                              fontSize: 14.sp,
                                              fontWeight: FontWeight.bold,
                                            ),
                                          ),

                                        // 中心点
                                        AnimatedBuilder(
                                          animation: _scaleAnimation,
                                          builder: (context, child) {
                                            return Transform.scale(
                                              scale: _scaleAnimation.value,
                                              child: Container(
                                                width: 15.w,
                                                height: 15.h,
                                                decoration: const BoxDecoration(
                                                  color: Color(0xFFCDFF5F),
                                                  shape: BoxShape.circle,
                                                ),
                                              ),
                                            );
                                          },
                                        ),
                                      ],
                                    ),
                                  ),
                                  SizedBox(height: 20.h),
                                  TweenAnimationBuilder<double>(
                                    duration: const Duration(milliseconds: 500),
                                    tween: Tween<double>(begin: 0.9, end: 1.0),
                                    curve: Curves.easeInOut,
                                    builder: (context, value, child) {
                                      return Transform.scale(
                                        scale: value,
                                        child: Text(
                                          controller
                                                  .recognition_stage
                                                  .value
                                                  .isNotEmpty
                                              ? controller
                                                    .recognition_stage
                                                    .value
                                              : "Identifying plants...",
                                          style: TextStyle(
                                            color: const Color(0xFFCDFF5F),
                                            fontSize: 16.sp,
                                            fontWeight: FontWeight.w500,
                                          ),
                                        ),
                                      );
                                    },
                                  ),
                                  SizedBox(height: 8.h),
                                  AnimatedOpacity(
                                    opacity:
                                        0.7 +
                                        (0.3 *
                                            (controller
                                                .recognition_progress
                                                .value)),
                                    duration: const Duration(milliseconds: 300),
                                    child: Text(
                                      "Please wait patiently",
                                      style: TextStyle(
                                        color: Colors.white,
                                        fontSize: 12.sp,
                                      ),
                                    ),
                                  ),
                                  SizedBox(height: 10.h),
                                  SizedBox(
                                    width: 200.w,
                                    child: ClipRRect(
                                      borderRadius: BorderRadius.circular(10),
                                      child: Stack(
                                        children: [
                                          // 线性进度指示器
                                          LinearProgressIndicator(
                                            minHeight: 8,
                                            backgroundColor: Colors.white
                                                .withOpacity(0.2),
                                            valueColor:
                                                const AlwaysStoppedAnimation<
                                                  Color
                                                >(Color(0xFFCDFF5F)),
                                            value: controller
                                                .recognition_progress
                                                .value,
                                          ),

                                          // 动画移动的光点效果
                                          AnimatedBuilder(
                                            animation: _shimmerAnimation,
                                            builder: (context, child) {
                                              return Positioned(
                                                left: _shimmerAnimation.value.w,
                                                top: 0,
                                                bottom: 0,
                                                child: Container(
                                                  width: 20.w,
                                                  decoration: BoxDecoration(
                                                    gradient: LinearGradient(
                                                      colors: [
                                                        Colors.white
                                                            .withOpacity(0),
                                                        Colors.white
                                                            .withOpacity(0.5),
                                                        Colors.white
                                                            .withOpacity(0),
                                                      ],
                                                    ),
                                                  ),
                                                ),
                                              );
                                            },
                                          ),

                                          // 分段线
                                          Positioned(
                                            top: 0,
                                            bottom: 0,
                                            left: 5,
                                            right: 5,
                                            child: AnimatedOpacity(
                                              duration: const Duration(
                                                milliseconds: 700,
                                              ),
                                              opacity:
                                                  controller
                                                          .recognition_progress
                                                          .value >
                                                      0.1
                                                  ? 1.0
                                                  : 0.0,
                                              child: Row(
                                                mainAxisAlignment:
                                                    MainAxisAlignment
                                                        .spaceBetween,
                                                children: List.generate(
                                                  10,
                                                  (index) => Container(
                                                    width: 2,
                                                    color: Colors.white
                                                        .withOpacity(0.3),
                                                  ),
                                                ),
                                              ),
                                            ),
                                          ),
                                        ],
                                      ),
                                    ),
                                  ),
                                  SizedBox(height: 10.h),
                                ],
                              ),
                            ),
                          ),
                        );
                      },
                    ),
                  ),
                )
              else if (!isLoading)
                filteredSections.isEmpty
                    ? SizedBox(
                        height: 400.h,
                        child: Center(
                          child: Text(
                            "No plant information found",
                            style: TextStyle(
                              color: const Color(0xFFCDFF5F),
                              fontSize: 16.sp,
                              fontWeight: FontWeight.w500,
                            ),
                          ),
                        ),
                      )
                    : Padding(
                        padding: EdgeInsets.symmetric(horizontal: 24.w),
                        child: Column(
                          children: filteredSections.map((section) {
                            Color cardColor;
                            Color textColor = Colors.black87;
                            Color titleColor = const Color(0xFF2F6705);
                            IconData sectionIcon;

                            // Assign different colors and icons for each section type
                            switch (section["title"]) {
                              case "Name":
                                cardColor = const Color(0xFFCDFF5F);
                                sectionIcon = Icons.eco;
                                break;
                              case "Care Info":
                                cardColor = const Color(0xFFB8F03E);
                                sectionIcon = Icons.spa;
                                break;
                              case "Flowering Time":
                                cardColor = const Color(0xFFD6FF7F);
                                sectionIcon = Icons.calendar_today;
                                break;
                              case "Common Problems":
                                cardColor = const Color(0xFFAFE233);
                                sectionIcon = Icons.warning_rounded;
                                break;
                              case "Confidence":
                                cardColor = const Color(0xFFE1FFA0);
                                sectionIcon = Icons.verified;
                                break;
                              default:
                                cardColor = const Color(0xFFCDFF5F);
                                sectionIcon = Icons.info_outline;
                            }

                            return Container(
                              margin: EdgeInsets.symmetric(vertical: 8.h),
                              decoration: BoxDecoration(
                                color: cardColor,
                                borderRadius: BorderRadius.circular(15.r),
                                boxShadow: [
                                  BoxShadow(
                                    color: Colors.black.withOpacity(0.15),
                                    blurRadius: 10,
                                    offset: const Offset(0, 4),
                                  ),
                                ],
                                border: Border.all(
                                  color: Colors.white.withOpacity(0.5),
                                  width: 1.5,
                                ),
                              ),
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  // Section title with icon
                                  if (section["title"] != "Care Info" ||
                                      filteredSections.length > 1)
                                    Container(
                                      width: double.infinity,
                                      padding: EdgeInsets.symmetric(
                                        horizontal: 16.r,
                                        vertical: 12.r,
                                      ),
                                      decoration: BoxDecoration(
                                        color: Colors.black.withOpacity(0.05),
                                        borderRadius: BorderRadius.only(
                                          topLeft: Radius.circular(15.r),
                                          topRight: Radius.circular(15.r),
                                        ),
                                      ),
                                      child: Row(
                                        children: [
                                          Icon(
                                            sectionIcon,
                                            color: titleColor,
                                            size: 22.sp,
                                          ),
                                          SizedBox(width: 8.w),
                                          Text(
                                            section["title"]!,
                                            style: TextStyle(
                                              fontWeight: FontWeight.bold,
                                              fontSize: 17.sp,
                                              color: titleColor,
                                              letterSpacing: 0.5,
                                            ),
                                          ),
                                        ],
                                      ),
                                    ),

                                  // Handle content differently based on type
                                  Builder(
                                    builder: (context) {
                                      final content = section["content"]!;

                                      // For multi-line content, use paragraph styling
                                      if (content.contains("\n") ||
                                          content.length > 100) {
                                        return Padding(
                                          padding: EdgeInsets.all(16.r),
                                          child: Column(
                                            crossAxisAlignment:
                                                CrossAxisAlignment.start,
                                            children: content
                                                .split("\n")
                                                .where(
                                                  (paragraph) => paragraph
                                                      .trim()
                                                      .isNotEmpty,
                                                )
                                                .map((paragraph) {
                                                  return Padding(
                                                    padding: EdgeInsets.only(
                                                      bottom: 12.h,
                                                    ),
                                                    child: Text(
                                                      paragraph.trim(),
                                                      style: TextStyle(
                                                        fontSize: 14.sp,
                                                        color: textColor,
                                                        height: 1.5,
                                                      ),
                                                    ),
                                                  );
                                                })
                                                .toList(),
                                          ),
                                        );
                                      }
                                      // For Name and Confidence, use special highlight styling
                                      else if (section["title"] == "Name" ||
                                          section["title"] == "Confidence") {
                                        return Container(
                                          width: double.infinity,
                                          padding: EdgeInsets.all(16.r),
                                          child: Text(
                                            content,
                                            style: TextStyle(
                                              fontSize: 16.sp,
                                              fontWeight:
                                                  section["title"] == "Name"
                                                  ? FontWeight.bold
                                                  : FontWeight.w500,
                                              color: textColor,
                                              height: 1.3,
                                            ),
                                            textAlign: TextAlign.center,
                                          ),
                                        );
                                      }
                                      // For other short content
                                      else {
                                        return Padding(
                                          padding: EdgeInsets.all(16.r),
                                          child: Text(
                                            content,
                                            style: TextStyle(
                                              fontSize: 14.sp,
                                              color: textColor,
                                              height: 1.5,
                                            ),
                                          ),
                                        );
                                      }
                                    },
                                  ),
                                ],
                              ),
                            );
                          }).toList(),
                        ),
                      ),
            ],
          ),
        ),
      );
    });
  }

  @override
  Widget build(BuildContext context) {
    // 离开后再进入时自动清空结果
    WidgetsBinding.instance.addPostFrameCallback((_) {
      if (controller.plant_name.value.isNotEmpty ||
          controller.result_text.value.isNotEmpty) {
        controller.clear_result();
      }
    });
    return GetBuilder<AiController>(
      id: "ai",
      builder: (_) {
        return Scaffold(
          body: Container(
            decoration: const BoxDecoration(
              image: DecorationImage(
                image: AssetImage(AssetsImages.bg),
                fit: BoxFit.cover,
              ),
            ),
            child: SafeArea(
              bottom: false,
              top: false,
              child: Stack(
                children: [
                  _buildView(),

                  // 底部上传按钮 - 固定在底部
                  Positioned(
                    left: 0,
                    right: 20.w,
                    bottom: 125.h,
                    child: Align(
                      alignment: Alignment.topRight,
                      child: Obx(() {
                        final is_picking_image = controller.is_picking_image.value;
                        return GestureDetector(
                          onTap: () async {
                            await controller.pick_image();
                            if (controller.selected_image.value != null) {
                              await controller.recognize_plant();
                            }
                          },
                          child: Container(
                            width: 75.w,
                            height: 75.h,
                            decoration: BoxDecoration(
                              color: const Color(0xFFCDFF5F),
                              border: Border.all(
                                color: const Color(0xFFFFEE00),
                                width: 2.w,
                              ),
                              borderRadius: BorderRadius.circular(10.r),
                            ),
                            child: is_picking_image
                                ? Center(
                                    child: TweenAnimationBuilder<double>(
                                      duration: const Duration(
                                        milliseconds: 1500,
                                      ),
                                      tween: Tween<double>(
                                        begin: 0,
                                        end: 2 * 3.14,
                                      ),
                                      curve: Curves.linear,
                                      builder: (context, value, child) {
                                        return Transform.rotate(
                                          angle: value,
                                          child: Stack(
                                            alignment: Alignment.center,
                                            children: [
                                              SizedBox(
                                                width: 35.w,
                                                height: 35.h,
                                                child: CircularProgressIndicator(
                                                  valueColor:
                                                      const AlwaysStoppedAnimation<
                                                        Color
                                                      >(Colors.black),
                                                  strokeWidth: 2,
                                                ),
                                              ),
                                              Container(
                                                width: 10.w,
                                                height: 10.h,
                                                decoration: BoxDecoration(
                                                  color: const Color(
                                                    0xFFFFEE00,
                                                  ),
                                                  shape: BoxShape.circle,
                                                ),
                                              ),
                                            ],
                                          ),
                                        );
                                      },
                                      onEnd: () {}, // Auto-repeats
                                    ),
                                  )
                                : Column(
                                    children: [
                                      SizedBox(height: 20.h),
                                      SvgPicture.asset(AssetsImages.aiUpload),
                                      Text(
                                        "Upload",
                                        style: TextStyle(
                                          fontSize: 14.sp,
                                          fontWeight: FontWeight.w600,
                                          color: Colors.black,
                                        ),
                                      ),
                                    ],
                                  ),
                          ),
                        );
                      }),
                    ),
                  ),
                ],
              ),
            ),
          ),
        );
      },
    );
  }
}
